package com.qkl.xiatang.app.web.controller;

import com.qkl.xiatang.app.service.impl.*;
import com.qkl.xiatang.app.utils.AppSessionUtils;
import com.qkl.xiatang.app.utils.AppUtils;
import com.qkl.xiatang.app.utils.ErrorCodeUtils;
import com.qkl.xiatang.app.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("{app.baseURL}")
@Slf4j
public class TestController {

    @Autowired
    private PrintService printService;

    @Autowired
    private MessageService messageService;

    @Autowired
    private DahuaService dahuaService;

    @Autowired
    private FeedNoticeTestService feedNoticeTestService;

    /**
     * 网络打印
     * @param params
     * @return
     */
    @GetMapping("/print")
    public Result print(@RequestParam Map<String,Object> params){
        String content = StringUtils.trimToEmpty((String) params.get("content"));
        if(StringUtils.isEmpty(content)){
            return Result.error(ErrorCodeUtils.PARAM_EMPTY, ErrorCodeUtils.PARAM_EMPTY_MSG);
        }
        return Result.success("网络打印");
       // return ControllerHelper.toQueryResult(printService.printMsg(content));
    }

    /**
     * 查询消息推送设备
     * @return
     */
    @GetMapping("/queryMessagePushDevice")
    public Result queryMessagePushDevice(@RequestParam Map<String,String> params){
        String subType = StringUtils.trimToEmpty(params.get("subType"));
        String messageId = StringUtils.trimToEmpty(params.get("messageId"));
        return Result.success(messageService.queryMessagePushDevice(AppSessionUtils.getCompanyId(),AppUtils.parseInt(subType),messageId),"查询消息推送设备");
    }

    /**
     * 获取大华访问token
     * @return
     */
    @GetMapping("/getDahuaToken")
    public Result getDahuaToken(){
        return ControllerHelper.toQueryResult(dahuaService.getDahuaToken());
    }




    /**
     * 喂料、查料台通知
     * @param params
     * @return
     */
    @GetMapping("/testFeedNotice")
    public Result testFeedNotice(@RequestParam Map<String,String> params){
        feedNoticeTestService.testFeedNotice();
        return Result.success();
    }


}
